package com.einmeer.hfbank.controller;

import com.einmeer.hfbank.entity.User;
import com.einmeer.hfbank.service.UserService;
import com.einmeer.hfbank.vo.ResultVo;
import jakarta.annotation.Resource;
import org.apache.logging.log4j.util.PerformanceSensitive;
import org.springframework.web.bind.annotation.*;

/**
 * @author 芊嵛
 * @date 2024/1/11
 */

@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    /**
     * 登录(调试成功)
     * @param userPhone
     * @param userPassword
     * @return
     */
    @GetMapping("/login/{userPhone}/{userPassword}")
    @CrossOrigin
    public ResultVo login(@PathVariable("userPhone") Long userPhone, @PathVariable("userPassword") String userPassword) {
        System.out.println(userPhone+"  "+ userPassword);
        return userService.login(userPhone, userPassword);
    }

    /**
     * 注册密码，手机号(调试成功)
     * @param user
     * @return
     */
    @PostMapping("/register")
    @CrossOrigin
    public ResultVo register(@RequestBody User user) {
        return userService.register(user);
    }

    /**
     * 实名认证(调试成功)
     * @param userId
     * @param userName
     * @param userIDCard
     * @return
     */
    @PutMapping("/identification/{userId}/{userName}/{userIDCard}")
    @CrossOrigin
    public ResultVo identification(@PathVariable("userId") Long userId, @PathVariable("userName") String userName, @PathVariable("userIDCard") String userIDCard){
        return userService.identification(userId, userName, userIDCard);
    }

    /**
     * 修改昵称(调试成功)
     * @param userId
     * @param userOName
     * @return
     */
    @PutMapping("/changeUserOName/{userId}/{userOName}")
    @CrossOrigin
    public ResultVo changeUserOName(@PathVariable("userId") Long userId, @PathVariable("userOName") String userOName){
        return userService.changeUserOName(userId, userOName);
    }

    /**
     * 修改密码(调试成功)
     * @param userId
     * @param OldUserPassword
     * @param NewUserPassword
     * @return
     */
    @PutMapping("/changeUserPassword/{userId}/{OldUserPassword}/{NewUserPassword}")
    @CrossOrigin
    public ResultVo changeUserPassword(@PathVariable("userId") Long userId, @PathVariable("OldUserPassword") String OldUserPassword, @PathVariable("NewUserPassword") String NewUserPassword){
        return userService.changeUserPassword(userId, OldUserPassword, NewUserPassword);
    }

    /**
     * 查询个人信息(调试成功)
     * @param userId
     * @return
     */
    @GetMapping("/queryUserInfo/{userId}")
    @CrossOrigin
    public ResultVo queryUserInfo(@PathVariable("userId") Long userId){
        return userService.queryUserInfo(userId);
    }

    /**
     * 删除名义上删除(调试成功)
     * @param userId
     * @return
     */
    @PutMapping("/changeDelUser/{userId}")
    @CrossOrigin
    public ResultVo changeDelUser(@PathVariable("userId") Long userId){
        return userService.changeDelUser(userId);
    }

    /**
     * 根据用户id多表联查card
     * @param userId
     * @return
     */
    @GetMapping("/queryUserById/{userId}")
    @CrossOrigin
    public ResultVo queryUserById(@PathVariable("userId") Long userId) {
        return userService.queryUserById(userId);
    }

    /**
     * 忘记密码
     * @param userPhone
     * @param userPassword
     * @return
     */
    @PutMapping("/forgetPassword/{userPhone}/{userPassword}")
    @CrossOrigin
    public ResultVo forgetPassword(@PathVariable("userPhone") Long userPhone, @PathVariable("userPassword") String userPassword){
        return userService.forgetPassword(userPhone, userPassword);
    }

}
